package com.fitzone.web.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fitzone.common.enums.BusinessType;
import com.fitzone.common.exception.LoginFailedException;
import com.fitzone.common.result.Result;
import com.fitzone.model.dto.ActivityDTO;
import com.fitzone.model.dto.ActivityPageDTO;
import com.fitzone.model.entity.Activity;
import com.fitzone.model.entity.SysUser;
import com.fitzone.model.vo.ActivityVO;
import com.fitzone.model.vo.CourseVO;
import com.fitzone.web.annotation.Log;
import com.fitzone.web.service.ActivityService;
import com.fitzone.web.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/activity")
@Api(tags = "活动管理")
public class ActivityController {
    private final ActivityService activityService;

    @Log(title = "活动管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("添加操作")
    public Result save(@RequestBody ActivityDTO activityDTO){
        activityService.saveActivity(activityDTO);
        return Result.ok();
    }

    @Log(title = "活动管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改操作")
    public Result update(@RequestBody ActivityDTO activityDTO){
        activityService.updateActivity(activityDTO);
        return Result.ok();
    }
    @Log(title = "活动管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    @ApiOperation("删除操作")
    public Result delete(@PathVariable Long id){
        activityService.removeById(id);
        return Result.ok();
    }
    @GetMapping("/{page}/{limit}")
    @ApiOperation("查询操作")
    public Result<Page> page(ActivityPageDTO activityPageDTO) throws IOException {
        Page<Activity> pageInfo = activityService.page(activityPageDTO);
        return Result.ok(pageInfo);
    }

    @GetMapping("/list")
    @ApiOperation("查询操作")
    public Result<Page> pageSearch(ActivityPageDTO activityPageDTO) throws IOException {
        Page<Activity> pageInfo = activityService.page(activityPageDTO);
        return Result.ok(pageInfo);
    }

    @GetMapping("/updateStatus/{id}/{status}")
    @ApiOperation("更新状态")
    public Result<Activity> updateStatus(@PathVariable Long id,@PathVariable Integer status){
        activityService.updateStatus(id,status);
        return Result.ok();
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping("/{id}")
    public Result getId(@PathVariable Long id) {
        Activity activity = activityService.getById(id);
        return Result.ok(activity);
    }

}
